package inet.app.model.util;

import com.google.common.base.Preconditions;

import android.database.Cursor;


public class ContactUltil {

	/**
	 * Remove hyphen in phone number in Contact version 2.0
	 * 
	 * @param phoneNumber
	 *            The phone number of contact
	 * @return Return phone number without hyphen
	 */
	public static String removeHyphenInPhoneNumber(String phoneNumber) {
		Preconditions.checkNotNull(phoneNumber);

		String phoneNumberWithoutHyphen = "";
		String arr[] = phoneNumber.trim().split("-");

		if (arr.length > 0) {
			for (int i = 0; i < arr.length; i++) {
				phoneNumberWithoutHyphen += arr[i].toString().trim();
			}
		}
		return phoneNumberWithoutHyphen.equals("") ? phoneNumber : phoneNumberWithoutHyphen;
	}

	public static String getColumnValue(Cursor cursor, String columnName, String where) {
		String value = "";
		if (cursor != null) {
			if (cursor.moveToFirst()) {
				do {
					String columnValue = cursor.getString(cursor.getColumnIndex(columnName));
					if (columnValue.equalsIgnoreCase(where)) {
						value = columnValue;
						break;
					}
				} while (cursor.moveToNext());
			}
		}
		return value;
	}
}
